*** Supplemental replication file for:
*** "Workfare and Attitudes toward the Unemployed: New Evidence on Policy Feedback from 1990 to 2018"
*** Alexander Horn, Anthony Kevins, and Kees van Kersbergen
*** Comparative Political Studies

* NB: Replication file created in Stata version 15.1

**Note: Set working directory to location of data file first**

*************
*Thermostatic Analysis
*************


use "Workfare - Thermostatic Analysis.dta", clear

encode country, gen(country_num)
xtset country_num

egen cntrydummy = group(country)

sort cntrydummy year

egen countryyear=group(country year)

* Generate country mean 
gen mean_attitudes =. 
quietly foreach c of numlist 1/46 { 
	
	summarize unemp_job_refusal if countryyear == `c' [w=weight], detail 
	replace mean_attitudes  = r(mean) if countryyear == `c'
} 

duplicates drop country year, force

gen mean_left_gov =. 
quietly foreach c of numlist 1/14 { 
	
	summarize gov_left2 if cntrydummy == `c'  & interim == 1 , detail 
	replace mean_left_gov  = r(mean) if cntrydummy == `c' & wave == 3
	summarize gov_left2 if cntrydummy == `c'  & interim == 2 , detail 
	replace mean_left_gov  = r(mean) if cntrydummy == `c' & wave == 4
	summarize gov_left2 if cntrydummy == `c'  & interim == 3 , detail 
	replace mean_left_gov  = r(mean) if cntrydummy == `c' & wave == 5
} 

gen mean_unemp =. 
quietly foreach c of numlist 1/14 { 
	
	summarize unemp if cntrydummy == `c'  & interim == 1 , detail 
	replace mean_unemp  = r(mean) if cntrydummy == `c' & wave == 3
	summarize unemp if cntrydummy == `c'  & interim == 2 , detail 
	replace mean_unemp  = r(mean) if cntrydummy == `c' & wave == 4
	summarize unemp if cntrydummy == `c'  & interim == 3 , detail 
	replace mean_unemp  = r(mean) if cntrydummy == `c' & wave == 5
} 

gen mean_unemp_pmp =. 
quietly foreach c of numlist 1/14 { 
	
	summarize unemp_pmp if cntrydummy == `c'  & interim == 1 , detail 
	replace mean_unemp_pmp  = r(mean) if cntrydummy == `c' & wave == 3
	summarize unemp_pmp if cntrydummy == `c'  & interim == 2 , detail 
	replace mean_unemp_pmp  = r(mean) if cntrydummy == `c' & wave == 4
	summarize unemp_pmp if cntrydummy == `c'  & interim == 3 , detail 
	replace mean_unemp_pmp  = r(mean) if cntrydummy == `c' & wave == 5
} 

gen mean_ =. 
quietly foreach c of numlist 1/14 { 
	
	summarize  if cntrydummy == `c'  & interim == 1 , detail 
	replace mean_  = r(mean) if cntrydummy == `c' & wave == 3 
	summarize  if cntrydummy == `c'  & interim == 2 , detail 
	replace mean_  = r(mean) if cntrydummy == `c' & wave == 4
	summarize  if cntrydummy == `c'  & interim == 3 , detail 
	replace mean_  = r(mean) if cntrydummy == `c' & wave == 5
} 


* Set data 
drop if mean_attitudes == . 

* Generate differences, lags, and percentage change variables 
by country (wave), sort: gen d_mean_attitudes = mean_attitudes - mean_attitudes[_n-1]
by country (wave), sort: gen d_sub_punitive_tally = sub_punitive_tally - sub_punitive_tally[_n-1]
by country (wave), sort: gen d_sub_enabling_tally = sub_enabling_tally - sub_enabling_tally[_n-1]
by country (wave), sort: gen d_punitive_tally = punitive_tally - punitive_tally[_n-1]
by country (wave), sort: gen d_enabling_tally = enabling_tally - enabling_tally[_n-1]

by country (wave), sort: gen l_mean_attitudes = mean_attitudes[_n-1]

by country (wave), sort: gen pchange_unemp = (unemp - unemp[_n-1])/unemp
by country (wave), sort: gen pchange_unemp_pmp = (unemp_pmp - unemp_pmp[_n-1])/unemp_pmp
by country (wave), sort: gen pchange_punitive_tally = (punitive_tally - punitive_tally[_n-1])/punitive_tally
by country (wave), sort: gen pchange_enabling_tally = (enabling_tally - enabling_tally[_n-1])/enabling_tally

*Set labels 
label variable enabling_tally "Enabling Tally"
label variable punitive_tally "Punitive Tally"
label variable unemp "Unemployment Rate"
label variable pchange_unemp "Change in Unemployment Rate"
label variable l_mean_attitudes "Lagged Attitudes"
label variable mean_left_gov "Mean Left Government"
label variable mean_unemp "Mean Unemployment"
label variable pchange_unemp "% Change Unemployment"
label variable mean_unemp_pmp "Mean Unemployment Expenditure"
label variable pchange_unemp_pmp "% Change Unemployment Expenditure"
label variable uegen "Unemployment Generosity"
label variable totgen "Welfare State Generosity"


*OA6 Table 1 
xtreg mean_attitudes enabling_tally punitive_tally unemp l_mean_attitudes uegen totgen, mle re 
est store est4d
xtreg mean_attitudes enabling_tally punitive_tally unemp  l_mean_attitudes if e(sample), mle re 
est store est3
xtreg mean_attitudes enabling_tally punitive_tally unemp if e(sample), mle re 
est store est2
xtreg mean_attitudes enabling_tally punitive_tally if e(sample), mle re
est store est1

esttab est1 est2 est3 est4d using "OA6 Table 1.rtf", replace b(%7.3f) se star(* .10 ** .05) nogap se(3) label nonumbers nogap onecell nobaselevels 

*OA6 Table 2

gen time_trend = year - 1980
label variable time_trend "Time Trend"

set more off
xtreg d_enabling_tally l_mean_attitudes mean_left_gov mean_unemp pchange_unemp mean_unemp_pmp pchange_unemp_pmp uegen totgen time_trend, mle re
est store est1
xtreg d_punitive_tally l_mean_attitudes mean_left_gov mean_unemp pchange_unemp mean_unemp_pmp pchange_unemp_pmp uegen totgen time_trend, mle re 
est store est2

esttab est1 est2 using "OA6 Table 2.rtf", replace b(%7.3f) se star(* .10 ** .05) nogap se(3) label nonumbers nogap onecell nobaselevels 




**********	
*Descriptives 
**********

use "Workfare - Descriptive Analysis.dta", clear

*xtset	
	xtset countryn year
	set level 95, permanently
	set more off
	
*select scheme
	set scheme plottig


*label var
label variable code_plus "Enabling reform" 
label variable code_minus "Punitive reform"

*exclude (rare) policy reversals (reviewer request)
replace code_plus = code_plus - 1 if countryn == 1 & year == 1999 | countryn == 3 & year == 1998 | countryn == 5 & year == 2001 | countryn == 9 & year == 2004 | countryn == 9 & year == 2011 | countryn == 17 & year == 2000 | countryn == 25 & year == 1998 | countryn == 26 & year == 2001 

*Figure 1
twoway (dropline code_plus year)(dropline code_minus year), by(country, note("")) legend(cols(2)) xtitle("")  

graph export "Figure 1.png", replace
*Note: some minor manual edits have been performed on the figure printed in the paper, solely for aesthetic purposes


*OA Table 1

*set missing to zero (counterproductive for descriptives) 
foreach x of varlist code_total code_plus code_minus{
  replace `x' = 0 if(`x' == .)
}

*gen partisanship	
gen gov_left_right= gov_right1 - gov_left1 
		
		*table 1 App, online
		xtpcse l.code_minus   year    i.countryn                , pa c(ar1) //
		eststo M4
		xtpcse l.code_plus    year    i.countryn                , pa c(ar1) //
		eststo M3
		xtpcse l.code_minus   year   gov_left_right i.countryn  , pa c(ar1) //
		eststo M8
		xtpcse l.code_plus    year   gov_left_right i.countryn  , pa c(ar1) //
		eststo M7

	esttab M3 M4 M7 M8 using "OA1 Table 1.rtf", r2(%9.6f) label nocons star(* 0.1 ** 0.05 *** 0.01) se replace
	*Note: country binary-variable results ommitted from the table printed in the paper
	
